<?php
require_once('./vendor/autoload.php');

$socketLocal = new \HemiFrame\Lib\WebSocket\WebSocket('localhost', '7001');
$socketLocal->on('receive', function (\HemiFrame\Lib\WebSocket\Client $client, $data) {
    echo 'local'."\n";
    var_dump($data);
});

$socketRemote = new \HemiFrame\Lib\WebSocket\WebSocket('localhost', '7002');
$socketRemote->on('receive', function (\HemiFrame\Lib\WebSocket\Client $client, $data) {
    echo 'remote'."\n";
    var_dump($data);
});

$localClient = $socketLocal->connect();
if ($localClient !== false) {
//    $socketLocal->on('receive', function (\HemiFrame\Lib\WebSocket\Client $client, $data) use ($socketRemote) {
//        $data = json_decode($data, true);
//        var_dump($data);
//        $clients = $socketRemote->getClients();
//        var_dump($clients);
//        foreach ($clients as $client) {
//            $socketRemote->sendData($client, $data, false);
//        }
//    });
    $data = [
        'event' => 'broadcast'
    ];
    while (true) {
        $socketLocal->sendData($localClient, json_encode($data));
        sleep(5);
    }
}